setwd("~/Desktop/Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering")
# Importing the dataset
dataset = red.csv('Mall_Customers.csv')
setwd("~/Desktop/Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering")
# Importing the dataset
dataset = read.csv('Mall_Customers.csv')
View(dataset)
dataset = dataset[4:5]
# Using the elbow method to find the optimal number of clusters
set.seed(6)
wcss = vector()
for (i in 1:10) wcss[i] = sum(kmeans(dataset, i)$withinss)
plot(1:10,
wcss,
type = 'b',
main = paste('The Elbow Method'),
xlab = 'Number of clusters',
ylab='WCSS'
)
# Fitting K-Means to the dataset
set.seed(29)
kmeans = kmeans( x= dataset, centers = 5)
y_kmeans = kmeans$cluster
library("cluster", lib.loc="/Library/Frameworks/R.framework/Versions/3.4/Resources/library")
# Visualising the clusters
library(cluster)
clusplot(dataset,
y_kmeans,
lines = 0,
shade = TRUE,
color = TRUE,
labels = 2,
plotchar = FALSE,
span = TRUE,
main - paste('Clusters of customers'),
xlab = 'Annual Income',
ylab = 'Spending Score')
# Importing the dataset
dataset = read.csv('Mall_Customers.csv')
dataset = dataset[4:5]
# Using the elbow method to find the optimal number of clusters
set.seed(6)
wcss = vector()
for (i in 1:10) wcss[i] = sum(kmeans(dataset, i)$withinss)
plot(1:10,
wcss,
type = 'b',
main = paste('The Elbow Method'),
xlab = 'Number of clusters',
ylab='WCSS'
)
# Fitting K-Means to the dataset
set.seed(29)
kmeans = kmeans( x= dataset, centers = 5)
y_kmeans = kmeans$cluster
# Visualising the clusters
library(cluster)
clusplot(dataset,
y_kmeans,
lines = 0,
shade = TRUE,
color= TRUE,
labels = 2,
plotchar = FALSE,
span = TRUE,
main = paste('Clusters of customers'),
xlab = 'Annual Income',
ylab = 'Spending Score')
# K-Means Clustering
# Importing the dataset
dataset = read.csv('Mall_Customers.csv')
dataset = dataset[4:5]
# Using the elbow method to find the optimal number of clusters
set.seed(6)
wcss = vector()
for (i in 1:10) wcss[i] = sum(kmeans(dataset, i)$withinss)
plot(1:10,
wcss,
type = 'b',
main = paste('The Elbow Method'),
xlab = 'Number of clusters',
ylab='WCSS'
)
# Fitting K-Means to the dataset
set.seed(29)
kmeans = kmeans( x= dataset, centers = 5)
y_kmeans = kmeans$cluster
# Visualising the clusters
library(cluster)
clusplot(dataset,
y_kmeans,
lines = 0,
shade = TRUE,
color= TRUE,
labels = 2,
plotchar = FALSE,
span = TRUE,
main = paste('Clusters of customers'),
xlab = 'Annual Income',
ylab = 'Spending Score')
setwd("~/Desktop/Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering")
setwd("~/Desktop/Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering")
# Importing the dataset
dataset <- read.csv('Mall_Customers.csv')
View(dataset)
X <- dataset[4:5]
setwd("~/Desktop/Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering")
# Importing the dataset
dataset <- read.csv('Mall_Customers.csv')
View(dataset)
View(dataset)
View(dataset)
X <- dataset[4:5]
View(X)
# Using the elbow method to find the optimal number of clusters
set.seed(6)
wcss = vector()
for (i in 1:10) wcss[i] = sum(kmeans(X, i)$withinss)
plot(1:10,
wcss,
type = 'b',
main = paste('The Elbow Method'),
xlab = 'Number of cluster',
ylab = 'WCSS')
# Fitting K-Means to the dataset
set.seed(29)
kmeans = kmeans(X, 5, iter.max =300, nstart =10)
y_kmeans = kmeans$cluster
# Visualising the clusters
library(cluster)
clusplot(X,
y_kmeans,
lines = 0,
shade = TRUE,
color = TRUE,
labels =2,
plotchar = FALSE,
span = TRUE,
main = paste('Clusters of customers'),
xlab = 'Annual Income',
ylab = 'Spending Score')
# K-Means Clustering
# Importing the dataset
dataset <- read.csv('Mall_Customers.csv')
X <- dataset[4:5]
# Using the elbow method to find the optimal number of clusters
set.seed(6)
wcss = vector()
for (i in 1:10) wcss[i] = sum(kmeans(X, i)$withinss)
plot(1:10,
wcss,
type = 'b',
main = paste('The Elbow Method'),
xlab = 'Number of cluster',
ylab = 'WCSS')
# Fitting K-Means to the dataset
set.seed(29)
kmeans = kmeans(X, 5, iter.max =300, nstart =10)
y_kmeans = kmeans$cluster
# Visualising the clusters
library(cluster)
clusplot(X,
y_kmeans,
lines = 0,
shade = TRUE,
color = TRUE,
labels =2,
plotchar = FALSE,
span = TRUE,
main = paste('Clusters of customers'),
xlab = 'Annual Income',
ylab = 'Spending Score')
